from django.contrib.auth.models import BaseUserManager, UserManager, AbstractBaseUser, PermissionsMixin
from django.core import validators
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

class UserProxyManager(BaseUserManager):
    pass


class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField((_('username')),
                                max_length=64,
                                unique=True,
                                help_text=(_('Required. 64 characters or fewer. Letters, digits and underlined only.')),
                                validators=[
                                    validators.RegexValidator('^[a-zA-Z0-9_]+$', _(
                                        'Enter a valid openid. This value may contain only letters, numbers and underlined characters.'),
                                                              'invalid')],
                                error_messages={'unique': _('A user with that openid already exists.')})
    nickname = models.CharField((_('nick name')),
                                max_length=64,
                                blank=True,
                                help_text=(_('Required. 64 characters or fewer.')))
    is_staff = models.BooleanField((_('staff status')),
                                   default=False,
                                   help_text=(_('Designates whether the user can log into this admin site.')))
    is_active = models.BooleanField((_('active')),
                                    default=True,
                                    help_text=(_(
                                        'Designates whether this user should be treated as active. Unselect this instead of deleting accounts.')))
    date_joined = models.DateTimeField((_('date joined')),
                                       default=(timezone.now))
    objects = UserManager()
    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['nickname']

    class Meta:
        db_table = 'account_user'
        verbose_name = _('user')
        verbose_name_plural = _('users')


class UserProxy(User):
    objects = UserProxyManager()

    class Meta:
        proxy = True
